<?php
/**
 * Created by PhpStorm.
 * User: 图图
 * Date: 2021-6-11
 * Time: 14:54
 */
namespace app\common\model;

use think\Model as ThinkModel;
use think\Db;

/**
 *  用户 订单模型 (项目与商品共用)
**/
class VipOrder extends ThinkModel
{

    /**
     *  创建 项目单
     * @param $user_id          用户id
     * @param $store_id         门店id
     * @param $ids              项目id
     * @param string $roomid
     * @return array
     */
    public function toPjAdd($user_id,$store_id, $ids,$roomid='0')
    {
        $result = [
            'status' => false,
            'data' => [],
            'msg' => ''
        ];
        $order = [];
        $order['uv_id']         = $user_id;
        $order['store_id']         = $store_id;
        $order['room_id']         = $roomid;
        $order['hand_card_id']    = 0;
        $order['cashier_id']     = 0;
        $order['status']         = 1;
        $order['order_no']      = c_order_sn(1);
        $order['pay_no']        = p_order_sn(1);

        $Cart = new Cart();
        $checkOut = $Cart->outInfo($roomid,$user_id,$store_id,1,$ids);
        if(!$checkOut['status']) {
            $result['msg'] = $checkOut['msg'];
            return $result;
        }
        $info = $checkOut['data'];
        $order['payment_price']  = $info['order_amount'];
        $order['total_price']  = $info['goods_amount'];
        $order['total_num']     = $info['total_nums'];
        $order['created_time']   = time();

        $detailsItems = [];
        foreach($info['list'] as $k=>$v)
        {
            $detailsItems[] = [
                'project_id'            => $v['goodsInfo']['id'],
                'room_id'               => $roomid,
                'hand_card_id'          => 0,
                'order_type'            => 1,
                'num'                   => $v['num'],
                'name'                  => $v['goodsInfo']['goods_name'],
                'price'                 => $v['goodsInfo']['goods_price'],
                'payment_price'         => bcmul($v['goodsInfo']['goods_price'],$v['num'],2),
                'status'                => 1,
                'created_time'          => time(),
            ];
        }
        Db::startTrans();
        try{

            $order_id = Order::insertGetId($order);

            //记录下 订单ID
            foreach($detailsItems as $k=>$v){
                $detailsItems[$k]['order_id'] = $order_id;
            }
            $Orderproject = new Orderproject();
            $Orderproject->insertAll($detailsItems);

            //订单生成核销码
            $url      = 'https://www.baidu.com/'.'?order_id='.$order_id;
            $path     = 'uploads/project_order/';
            $filename = 'pj_order_id_'.$order_id.'.png';
            create_ewm($url,$path,$filename,6);
            Db::commit();
            $result['status']   = true;
            $result['msg']      = '下单成功';
            $result['data']     = $order_id;
            return $result;
        }catch(\Exception $e){
            Db::rollback();
            $result['msg'] = $e->getMessage();
            return $result;
        }
    }


    /**
     *  创建 商品单
     **/
    public function toPdAdd($user_id,$store_id, $ids,$roomid='0',$content='')
    {
        $result = [
            'status' => false,
            'data' => [],
            'msg' => ''
        ];
        $order = [];
        $order['uv_id']         = $user_id;
        $order['store_id']      = $store_id;
        $order['room_id']       = $roomid;
        $order['hand_card_id']  = 0;
        $order['cashier_id']    = 0;
        $order['status']        = 1;
        $order['order_no']      = c_order_sn(2);
        $order['pay_no']        = p_order_sn(2);
        $Cart = new Cart();

        $checkOut = $Cart->outInfo($roomid,$user_id,$store_id,2,$ids);

        if(!$checkOut['status'])
        {
            $result['msg'] = $checkOut['msg'];
            return $result;
        }
        $info = $checkOut['data'];

        $order['payment_price']     = $info['order_amount'];
        $order['goods_price']       = $info['goods_amount'];
        $order['create_time']       = time();
        $order['content']           = $content;

        $detailsItems = [];
        foreach($info['list'] as $k=>$v)
        {
            $detailsItems[] = [
                'goods_id'               => $v['goodsInfo']['id'],
                'store_id'               => $store_id,
                'goods_name'             => $v['goodsInfo']['goods_name'],
                'goods_price'            => $v['goodsInfo']['goods_price'],
                'payment_price'          => bcmul($v['goodsInfo']['goods_price'],$v['num'],2),
                'goods_num'              => $v['num'],
                'create_time'           => time(),
            ];
        }

        //echo '1111';die;
        Db::startTrans();
        try{

            $order_id = ProductOrder::insertGetId($order);

            //记录下 订单ID
            foreach($detailsItems as $k=>$v){
                $detailsItems[$k]['order_id'] = $order_id;
            }
            $ProductOrderItem = new ProductOrderItem();
            $ProductOrderItem->insertAll($detailsItems);

            Db::commit();
            $result['status']   = true;
            $result['msg']      = '下单成功';
            $result['data']     = $order_id;


            //下单成功后，减少购物车商品数量
            $cart = new Cart();
            $cart->del($roomid,$user_id,$store_id, $ids);


            return $result;
        }catch(\Exception $e){
            Db::rollback();
            $result['msg'] = $e->getMessage();
            return $result;
        }
    }


    /**
     * 呼叫技师
     * @param $user_id     用户id
     * @param $room_id     房间id
     * @param $engineer_id  技师ID
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function callEngineer($user_id, $room_id,$engineer_id,$project_id){
        $room = Db::name('qt_room')->where('id',$room_id)->find();

        $project_arr = explode(',',$project_id);

        foreach ($project_arr as $k => $v) {

            $project_name = Db::name('qt_project')->where('id',$v)->value('name');

            Db::name('qt_message')->insert([
                'user_id'=>$user_id,//发起人
                'room_id'=>$room['name'] ?? '',
                'to_user_id'=>$engineer_id,//接收人
                'content'=>'房间:'.$room['name'].' 正在呼叫 '.$project_name,
                'status'=>1,//状态  1 正常 2 已通过 3 未通过
                'type'=>2,//2 呼叫服务消息
                'created_time'=>time(),
            ]);
        }
    }


    /**
     *  房间码 ->  点技师 下单
     **/
    public function spotAdd($user_id,$store_id, $room_id,$engineer_id,$project_id)
    {
        $result = [
            'status' => false,
            'data' => [],
            'msg' => ''
        ];
        $order = [];
        $order['uv_id']         = $user_id;
        $order['store_id']      = $store_id;
        $order['room_id']       = $room_id;
        $order['hand_card_id']  = 0;
        $order['cashier_id']    = 0;
        $order['status']        = 1;
        $order['order_no']      = c_order_sn(1);
        $order['pay_no']        = p_order_sn(1);

        //获取项目信息
        $projectInfo = Project::where('id',$project_id)->find();

        if (empty($projectInfo)) {
            return [
                'status'=>false,
                'msg'=>'没有找到项目信息',
                $result['data'] = $project_id
            ];
        }

        $order['payment_price']  = $projectInfo['price'];
        $order['total_price']    = $projectInfo['price'];
        $order['total_num']      = 1;
        $order['created_time']   = time();

        $detailsItems = [];
        $detailsItems[] = [
            'project_id'            => $projectInfo['id'],
            'engineer_id'           => $engineer_id,
            'room_id'               => $room_id,
            'hand_card_id'          => 0,
            'order_type'            => 0,
            'num'                   => 1,
            'name'                  => $projectInfo['name'],
            'price'                 => $projectInfo['price'],
            'payment_price'         => bcmul($projectInfo['price'],1,2),
            'status'                => 1,
            'created_time'          => time(),
        ];

        Db::startTrans();
        try{
            $order_id = Order::insertGetId($order);
            //记录下 订单ID
            foreach($detailsItems as $k=>$v){
                $detailsItems[$k]['order_id'] = $order_id;
            }
            $Orderproject = new Orderproject();
            $Orderproject->insertAll($detailsItems);

            //改技师排位
            //写技师房列表
            $max_sort = Db::name('qt_order_queue')->where(['store_id'=>$store_id])->lock(true)->max('sort');
            Db::name('qt_order_queue')->where(['user_id'=>$engineer_id])->update([
                'created_time'=>time(),
                'sort'=>$max_sort+1,
                'status'=>2,
            ]);

            //改技师状态
            Db::name('qt_users')->where(['id'=>$engineer_id])->update(['work_status'=>5]);
            Db::name('qt_room')->where(['id'=>$room_id])->update(['status_id'=>2]);

            //呼叫技师
            $this->callEngineer($user_id, $room_id,$engineer_id,$project_id);

            Db::commit();

            $result['status']   = true;
            $result['msg']      = '下单成功';
            $result['data']     = $order_id;
            return $result;
        }catch(\Exception $e){
            Db::rollback();
            $result['msg'] = $e->getMessage();
            return $result;
        }
    }


    /**
     *  自助结账 信息
     **/
    public function selfOrderInfo($user_id,$store_id, $room_id)
    {
        $result = [
            'status' => false,
            'msg'    => '',
            'data' =>[
                'order_id'    => 0,             //项目订单ID
                'product_ids' => "",            //商品订单ID集合
                'total_money' => 0.00,          //总金额
                'total_num'   => 0,             //总件数
                'list'        => [],            //项目与商品列表
            ]
        ];

        //获取房间信息
        $roomInfo = Room::where('id',$room_id)->find();
        if(!$roomInfo)
        {
            $result['msg'] = '房间不存在';
            return $result;
        }

        $room_name = $roomInfo['name'];
        //查询正在服务未结束的项目单信息
        $order_where[] = ['uv_id','eq',$user_id];
        $order_where[] = ['store_id','eq',$store_id];
        $order_where[] = ['room_id','eq',$room_id];
        //$order_where[] = ['status','in','1,2,3'];
        //$order_where[] = ['pay_status','eq',1];
        $orderInfo = Order::where($order_where)->find();

        if($orderInfo)
        {
            //if($orderInfo['pay_status'] == 1)
            //{
                $result['data']['order_id'] = $orderInfo['id'];
            //}
            //获取项目详情信息
            $orderItem = Orderproject::alias('op')
                        ->leftJoin('qt_users e','e.id = op.engineer_id')
                        ->where(['order_id'=>$orderInfo['id']])
                        ->field('op.*,e.real_name')
                        ->order('id asc')
                        ->select();
            if($orderItem)
            {
                foreach($orderItem as $k=>$v)
                {
                    $result['data']['list'][] = [
                        'room_name'     => $room_name,
                        'real_name'     => $v['real_name'],
                        'name'          => $v['name'],
                        'price'         => $v['price'],
                        'payment_price' => $v['payment_price'],
                        'num'           => $v['num'],
                        'type'          => 1,
                    ];

                    //由于自助结账中存在已支付与未支付同时存在,在这里只累计计算未支付的金额
                    if($orderInfo['pay_status'] == 1)
                    {
                        $result['data']['total_money'] = bcadd($result['data']['total_money'],$orderInfo['payment_price'],2);
                        $result['data']['total_num']   = bcadd($result['data']['total_num'],$v['num'],0);
                    }

                }
            }
        }

        //获取商品订单信息
        $product_where[] = ['uv_id','eq',$user_id];
        $product_where[] = ['store_id','eq',$store_id];
        $product_where[] = ['room_id','eq',$room_id];
        //$product_where[] = ['order_status','in','0,1'];
        //$product_where[] = ['pay_status','eq',0];
        $productInfo = ProductOrder::where($product_where)->select();
        if($productInfo)
        {
            foreach($productInfo as $k=>$v)
            {
                if($v['pay_status'] == 0)
                {
                    $result['data']['product_ids'] .= $v['id'].',';
                }
                //获取商品详情
                $productItem = ProductOrderItem::where(['order_id'=>$v['id']])->select();
                if($productItem)
                {
                    foreach($productItem as $kk=>$vv)
                    {
                        $result['data']['list'][] = [
                            'room_name'     => $room_name,
                            'real_name'     => "",
                            'name'          => $vv['goods_name'],
                            'price'         => $vv['goods_price'],
                            'payment_price' => $vv['payment_price'],
                            'num'           => $vv['goods_num'],
                            'type'          => 2,
                        ];

                        //由于自助结账中存在已支付与未支付同时存在,在这里只累计计算未支付的金额
                        if($v['pay_status'] == 0)
                        {

                            $result['data']['total_money'] = bcadd($result['data']['total_money'],$v['payment_price'],2);
                            $result['data']['total_num']   = bcadd($result['data']['total_num'],$vv['goods_num'],0);
                        }

                    }
                }

            }
        }

        $result['data']['product_ids'] = trim($result['data']['product_ids'],',');

        $result['status'] = true;
        return $result;
    }



    /**
     *  自助结账 下单
    **/
    public function createSelf($user_id,$store_id, $room_id,$order_id,$product_ids)
    {
        $result = [
            'status'    => false,
            'msg'       => '',
            'data'      => [],
        ];

        $info = $this->selfOrderInfo($user_id,$store_id, $room_id);
        if(!$info['status'])
        {
            return false;
        }

        //检查是否有正在进行的项目单或 未支付的商品单
        if(count($info['data']['list']) == 0)
        {
            return false;
        }

        $order['order_no']      = c_order_sn(3);
        $order['pay_no']        = p_order_sn(3);
        $order['uv_id']        =  $user_id;
        $order['store_id']     =  $store_id;
        $order['room_id']      =  $room_id;
        $order['order_id']     =  $order_id;
        $order['product_ids']  =  $product_ids;
        $order['goods_amount'] =  $info['data']['total_money'];
        $order['order_amount'] =  $info['data']['total_money'];
        $order['create_time']  =  time();


        Db::startTrans();
        try{

            $order_id = Db::name('qt_parent_order')->insertGetId($order);

            Db::commit();
            $result['status']   = true;
            $result['data']     = $order_id;
            return $result;
        }catch (\Exception $e){
            $result['status']   = true;
            $result['msg']      = $e->getMessage();
            return $result;
        }


    }


    /**
     *  订单列表
    **/
    public function orderList($type,$user_id,$store_id,$status,$limit,$roomid='0')
    {
        $list = [];
        switch ($type)
        {
            case 1:
                $list =  $this->projectList($user_id,$store_id,$status,$limit,$roomid);
                break;
            case 2:
                $list =  $this->productList($user_id,$store_id,$status,$limit,$roomid);
                break;
        }

        return $list;
    }

    /**
     *  项目单列表
    **/
    public function projectList($user_id,$store_id,$status,$limit,$roomid='0')
    {
        //查询状态: 1=待消费   2=待付款  3=待评价  4=已完成
        $where[] = ['store_id','eq',$store_id];
        if(!empty($roomid)){
            $where[] = ['room_id','eq',$roomid];
        }
        switch ($status)
        {
            case 1:
                $where[] = ['o.status','eq',1];
                $where[] = ['o.pay_status','eq',2];
                break;
            case 2:
                $where[] = ['o.status','eq',1];
                $where[] = ['o.pay_status','eq',1];
                break;
            case 3:
                $where[] = ['o.status','eq',5];
                break;
            case 4:
                $where[] = ['o.status','eq',4];
                break;
        }


        $list = Order::alias('o')
                ->leftJoin('qt_store s','s.id = o.store_id')
                ->where($where)
                ->field('o.id,o.order_no,o.uv_id,o.store_id,o.total_price,o.payment_price,o.status,o.created_time,s.name as store_name')
                ->order('o.id desc')
                ->paginate($limit)
                ->each(function($item){
                    $item['item_info']      = '';
                    $item['created_time']   = date('Y-m-d H:i:s',$item['created_time']);

                    //核销码
                    $item['pj_order_code']  = getUrl().'/uploads/project_order/pj_order_id_'.$item['id'].'.png';

                    return $item;
                });
        return $list->items();
    }

    /**
     *  商品单列表
     **/
    public function productList($user_id,$store_id,$status,$limit,$roomid='0')
    {
        //查询状态: 0=待支付  1=已支付  2=已完成
        $where[] = ['o.store_id','eq',$store_id];
        if(!empty($roomid)){
            $where[] = ['o.room_id','eq',$roomid];
        }
        switch ($status)
        {
            case 0:
                $where[] = ['o.order_status','eq',0];
                break;
            case 1:
                $where[] = ['o.order_status','eq',1];
                break;
            case 2:
                $where[] = ['o.order_status','eq',2];
                break;
        }

        $list = ProductOrder::alias('o')
            ->leftJoin('qt_store s','s.id = o.store_id')
            ->where($where)
            ->field('o.id,o.order_no,o.uv_id,o.store_id,o.order_status,o.create_time,s.name as store_name')
            ->order('o.id desc')
            ->paginate($limit)
            ->each(function($item){
                $data = ProductOrderItem::where('order_id',$item['id'])->select();
                $item['item_info']      = $data;
                $item['create_time'] = date('Y-m-d H:i:s',$item['create_time']);
                return $item;
            });
        return $list->items();
    }


    /**
     *  订单详情
    **/
    public function orderInfo($type,$user_id,$store_id,$id)
    {

        $where[] = ['id','eq',$id];
        $where[] = ['uv_id','eq',$user_id];
        $where[] = ['store_id','eq',$store_id];
        switch ($type)
        {
            case 1:
                $orderInfo = Order::where($where)->find();
                $orderInfo['item_info']      = '';
                if($orderInfo)
                {
                    $item = Orderproject::where('order_id',$id)->field('id,order_id,name,num,price,payment_price')->select();
                    $orderInfo['item'] = !empty($item) ? $item : [];
                }

                break;
            case 2:
                $orderInfo = ProductOrder::where($where)->find();
                $orderInfo['item_info']      = '';
                if($orderInfo)
                {
                    $item = ProductOrderItem::where('order_id',$id)->select();
                    $orderInfo['item'] = !empty($item) ? $item : [];
                }
                break;
        }

        return $orderInfo;
    }

    /**
     *  退款
    **/
    public function refund($type,$user_id,$store_id,$id)
    {
        $where[] = ['id','eq',$id];
        $where[] = ['uv_id','eq',$user_id];
        $where[] = ['store_id','eq',$store_id];
        switch ($type)
        {
            //项目单
            case 1:
                $where[] = ['status','eq',1];
                $where[] = ['pay_status','eq',1];
                $orderInfo = Order::where($where)->find();
                if(!$orderInfo)
                {
                    return false;
                }

                //进行退款
                Db::startTrans();
                try{

                    $orderEdit['status']        = 7;
                    $orderEdit['refund_time']   = time();

                    Order::where('id',$orderInfo['id'])->update($orderEdit);
                    Db::commit();
                    return true;
                }catch (\Exception $e){
                    Db::rollback();
                    return false;
                }

                break;
            //商品单
            case 2:
                $where[] = ['order_status','eq',1];
                $orderInfo = ProductOrder::where($where)->find();
                if(!$orderInfo)
                {
                    return false;
                }

                //进行退款

                Db::startTrans();
                try{

                    $orderEdit['order_status']  = 4;
                    $orderEdit['cancel_time']   = time();

                    ProductOrder::where('id',$orderInfo['id'])->update($orderEdit);

                    Db::commit();
                    return true;
                }catch (\Exception $e){
                    Db::rollback();
                    return false;
                }
                break;
        }
    }


    /**
     *  核销码 ->  销单
     * @param int       $source     来源:  1= 二维码   2= 订单号
     * @param int       $store_id   门店ID
     * @param int       $id         订单ID
     * @param string    $order_sn   订单号
     * @return  array
    **/
    public function orderSales($source = 1,$store_id,$id = 0,$order_sn = '')
    {
        $result = ['status'=>false,'msg'=>'','data'=>[]];

        switch ($source)
        {
            case 1:
                $name  = 'id';
                $value = $id;
                break;
            case 2:
                $name  = 'order_sn';
                $value = $order_sn;
                break;
        }

        $orderInfo = $this->where([$name=>$value,'store_id'=>$store_id])->find();
        if(!$orderInfo)
        {
            $result['msg'] = '订单不存在';
            return $result;
        }

        if($orderInfo['status'] == 4)
        {
            $result['msg'] = '此订单已服务结束';
            return $result;
        }

        $res = $this->where('id',$orderInfo['id'])->update(['status'=>4]);

        if($res)
        {
            $result['status'] = true;
            $result['msg']    = '核销成功';
            return $result;
        }else{
            $result['msg']    = '核销失败';
            return $result;
        }

    }


    /**
     *  取消订单
     **/
    public function cancel($type,$user_id,$store_id,$id)
    {

        $where[] = ['id','eq',$id];
        $where[] = ['uv_id','eq',$user_id];
        $where[] = ['store_id','eq',$store_id];
        switch ($type)
        {
            //项目单
            case 1:
                $where[] = ['status','eq',1];
                $where[] = ['pay_status','eq',1];
                $orderInfo = Order::where($where)->find();
                if(!$orderInfo)
                {
                    return false;
                }

                Db::startTrans();
                try{

                    $orderEdit['status']        = 6;
                    $orderEdit['cancel_time']   = time();

                    Order::where('id',$orderInfo['id'])->update($orderEdit);

                    Db::commit();
                    return true;
                }catch (\Exception $e){
                    Db::rollback();
                    return false;
                }

                break;
            //商品单
            case 2:
                $where[] = ['order_status','eq',0];
                $orderInfo = ProductOrder::where($where)->find();
                if(!$orderInfo)
                {
                    return false;
                }

                Db::startTrans();
                try{

                    $orderEdit['order_status']  = 3;
                    $orderEdit['cancel_time']   = time();
                    ProductOrder::where('id',$orderInfo['id'])->update($orderEdit);

                    Db::commit();
                    return true;
                }catch (\Exception $e){
                    Db::rollback();
                    return false;
                }
                break;
        }
    }




    /**
     *  订单支付
     **/
    public function pay($type,$user_id,$store_id,$id)
    {

        $where[] = ['id','eq',$id];
        $where[] = ['uv_id','eq',$user_id];
        $where[] = ['store_id','eq',$store_id];
        switch ($type)
        {
            //项目单
            case 1:
                $where[] = ['status','eq',1];
                $where[] = ['pay_status','eq',1];
                $orderInfo = Order::where($where)->find();
                if(!$orderInfo)
                {
                    return false;
                }

                Db::startTrans();
                try{

                    $orderEdit['pay_status']        = 2;
                    $orderEdit['pay_time']   = time();

                    Order::where('id',$orderInfo['id'])->update($orderEdit);

                    Db::commit();
                    return true;
                }catch (\Exception $e){
                    Db::rollback();
                    return false;
                }

                break;
            //商品单
            case 2:
                $where[] = ['order_status','eq',0];
                $orderInfo = ProductOrder::where($where)->find();
                if(!$orderInfo)
                {
                    return false;
                }

                Db::startTrans();
                try{

                    $orderEdit['order_status']  = 1;
                    $orderEdit['pay_status']  = 1;
                    $orderEdit['pay_time']   = time();
                    ProductOrder::where('id',$orderInfo['id'])->update($orderEdit);
                    Db::commit();
                    return true;
                }catch (\Exception $e){
                    Db::rollback();
                    return false;
                }
                break;
        }
    }



    /**
     *  查询用户当前进行中的订单信息
    **/
    public function carryOrder($store_id,$room_id)
    {
        $data = ['total_money'=>0.00,'nums'=>0,'list'=>[]];
        $where[] = ['store_id','eq',$store_id];
        $where[] = ['room_id','eq',$room_id];
        $where[] = ['status','in','1,2,3'];

        $order_id = Order::where($where)->column('id');

        if($order_id)
        {
            //获取订单详情列表
            $data['list'] = Orderproject::alias('op')
                ->leftJoin('qt_users e','e.id = op.engineer_id')
                ->leftJoin('qt_room r','r.id = op.room_id')
                //->leftJoin('qt_project p','p.id = op.project_id')
                ->whereIn('op.order_id',$order_id)
                ->field('op.*,e.real_name,r.name as room_name')
                ->order('id asc')
                ->select();
            if($data)
            {
                foreach($data['list'] as $k=>$v)
                {
                    $data['total_money'] = bcadd($data['total_money'],$v['payment_price'],2);
                    $data['nums']        = bcadd($data['nums'],$v['num'],0);
                }
            }

        }

        return $data;
    }

    /**
     * 获取退款订单记录
     */
    public function getRefundLog ($user_id,$store_id,$limit=10){

        $where[] = ['o.uv_id','eq',$user_id];
        $where[] = ['o.store_id','eq',$store_id];
        $where[] = ['o.status','eq',7];
        $orderInfo = Db::name('qt_order')
            ->alias('o')
            ->where($where)
            ->field(['o.id','o.uv_id','o.order_no','o.payment_price','o.status','o.refund_time','s.name as store_name'])
            ->leftJoin('qt_store s','o.store_id=s.id')
            ->paginate($limit)->each(function ($item){

                $item['refund_time'] = empty($item['refund_time']) ? '' : date('Y-m-d H:i:s',$item['refund_time']);

                return $item;
            });
        return $orderInfo;

    }


}